package com.leyou.item.controller;


import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.entity.CategoryBrand;
import com.leyou.item.service.CategoryBrandService;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品类目表，类目和商品(spu)是一对多关系，类目与品牌是多对多关系 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private CategoryBrandService categoryBrandService;

    //查询父类id
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> querycategoryBypid(@RequestParam("pid")Long pid){
        return ResponseEntity.ok(this.categoryService.querycategoryBypid(pid));
    }

    //查询category的id
    @GetMapping("/{id}")
    public ResponseEntity<CategoryDTO> querycategoryByid(@PathVariable("id")Long id){
        return ResponseEntity.ok(this.categoryService.querycategoryByid(id));
    }


    //根据id查询商品分类的集合

    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByIds(
            @RequestParam("ids") List<Long> ids){
        return ResponseEntity.ok(this.categoryService.querycategorylist(ids));
    }

    //根据品牌id 查询商品分类的集合
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> querybrandById(@RequestParam("id") Long bid){
        return ResponseEntity.ok(this.categoryBrandService.querybrandById(bid));
    }
}
